home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3850 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  999 b 

  1. Path: hubcap.clemson.edu!hubcap!mjs
  2. From: mjs@hubcap.clemson.edu (M. J. Saltzman)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Unable to check calloc's return values
  5. Date: 31 Jan 96 15:02:01 GMT
  6. Organization: Clemson University
  7. Message-ID: <mjs.823100521@hubcap>
  8. References: <4emept$ifv@hpg30a.csc.cuhk.hk> <9601311141.AA03713@dxmint.cern.ch>
  9. NNTP-Posting-Host: hubcap.clemson.edu
  10.  
  11. Dan Pop <danpop@mail.cern.ch> writes:
  12.  
  13. |>What's the right way to check the calloc's return value?
  14.  
  15. |    #include <stdlib.h>
  16. |    float **x;
  17. |    if ((x = calloc(9, sizeof(float *))) == NULL) exit(EXIT_FAILURE);
  18. |    /* or, using your style:
  19. |    if ((x = (float **) calloc(9, sizeof(float *))) == 0) exit(1);
  20. |    */
  21.  
  22. |Note that the effect of exit(1) is implementation defined.
  23. |There are implementations where it means successful termination.
  24.  
  25. Also, remember that initializing arrays of floats, doubles, or
  26. pointers using calloc() is not portable.
  27. -- 
  28.         Matthew Saltzman
  29.         Clemson University Math Sciences
  30.         mjs@clemson.edu
  31.